/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.close.hazard.service.impl;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.close.common.constant.HazardDicConstant;
import com.hopes.bizz.close.hazard.entity.ClosedAlarmHazardCarEntity;
import com.hopes.bizz.close.hazard.dto.ClosedAlarmHazardCarExcelDTO;
import com.hopes.bizz.close.hazard.vo.ClosedAlarmHazardCarExcelVO;
import com.hopes.bizz.close.hazard.mapper.ClosedAlarmHazardCarMapper;
import com.hopes.bizz.close.hazard.service.ClosedAlarmHazardCarService;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.SysDictEnum;
import com.hopes.boss.common.entity.ValidateImportBO;
import com.hopes.boss.common.excel.vo.ErrorMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
/**
 * 危险品车辆报警
 *
 * @author pig
 * @date 2023-10-31 16:03:39
 */
@Service
public class ClosedAlarmHazardCarServiceImpl extends ServiceImpl<ClosedAlarmHazardCarMapper, ClosedAlarmHazardCarEntity> implements ClosedAlarmHazardCarService {

    @Override
    public boolean handleAlarmById(ClosedAlarmHazardCarEntity closedAlarmHazardCar) {
        return lambdaUpdate()
                .set(ClosedAlarmHazardCarEntity::getHandleTime, closedAlarmHazardCar.getHandleTime())
                .set(ClosedAlarmHazardCarEntity::getHandleResult, closedAlarmHazardCar.getHandleResult())
                .set(ClosedAlarmHazardCarEntity::getHandlePerson, closedAlarmHazardCar.getHandlePerson())
                .set(ClosedAlarmHazardCarEntity::getHandleStatus, HazardDicConstant.CLOSE_HAZARD_ALARM_HANDLE_STATUS_DONE)
                .eq(ClosedAlarmHazardCarEntity::getId, closedAlarmHazardCar.getId()).update();
    }

    @Override
    public ValidateImportBO<ClosedAlarmHazardCarExcelDTO> validateImport(List<ClosedAlarmHazardCarExcelDTO> excelDTOList) {
        ValidateImportBO<ClosedAlarmHazardCarExcelDTO> bo = new ValidateImportBO<>();
        List<ErrorMessage> errorMessageList = new ArrayList<>();
        List<ClosedAlarmHazardCarExcelDTO> saveList = new ArrayList<>(excelDTOList);
        int successNum = excelDTOList.size();
        int failedNum = 0;

        bo.setErrorMessages(errorMessageList);
        bo.setSaveList(saveList);
        bo.setSuccessNum(successNum);
        bo.setFailedNum(failedNum);
        return bo;
    }

    @Override
    public ClosedAlarmHazardCarEntity importDtoToEntity(ClosedAlarmHazardCarExcelDTO excelDto) {
        ClosedAlarmHazardCarEntity entity= new ClosedAlarmHazardCarEntity();
        BeanUtils.copyProperties(excelDto, entity);
        return entity;
    }

    @Override
    public ClosedAlarmHazardCarExcelVO exportEntityToVo(ClosedAlarmHazardCarEntity entity) {
        ClosedAlarmHazardCarExcelVO excelVO = new ClosedAlarmHazardCarExcelVO();
        BeanUtils.copyProperties(entity, excelVO);
        excelVO.setIsNoticeStr(DictResolver.getItemLabelByValue(SysDictEnum.yes_no_type, entity.getIsNotice()));
        return excelVO;
    }


}
